<template>
	<view>
    <city-select
        @cityClick="cityClick"
        :formatName="formatName"
        :activeCity="location"
        :hotCity="hotCity"
        :obtainCitys="obtainCitys"
        :isSearch="true"
        ref="citys"
    ></city-select>
	</view>
</template>

<script>
	import {
		selectArea
	} from '@/api/home'
	export default {
		data() {
			return {
        //需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
        formatName: 'name',
        //当前城市
        activeCity: {
          id: 6501,
          name: '乌鲁木齐市'
        },
        //热门城市
        hotCity: [
          // {
          //   id: 6501,
          //   name: '乌鲁木齐市'
          // },
        ],
        //显示的城市数据
        obtainCitys: [],
				cityList: []
			}

		},
		onLoad() {
			this.getCity()
		},
    computed:{
      location: {
        get() {
          return this.$store.state.user.location
        },
        set() {
        }
      },
    },
		methods: {
      cityClick(item) {
        // uni.showToast({
        //   icon: 'none',
        //   title: 'item: ' + JSON.stringify(item),
        //   // #ifdef MP-WEIXIN
        //   duration: 3000,
        //   // #endif
        //   mask: true
        // })
        this.activeCity = item
        //存储当前城市
        uni.setStorageSync('location',item)
        //存储当前城市到vuex
        this.$store.commit('SET_LOCATION',item)
        uni.navigateBack({
          delta: 1
        })
      },
			getCity() {
				selectArea().then(res => {
					this.cityList = res.data;
          this.obtainCitys = res.data

				})
			},
		}
	}
</script>

<style lang="scss">
</style>
